﻿var toJsTest = setTimeout("")
if(typeof(ToolKit) == 'undefined'){
    //alert('ToolKit.Web.UI.WebControls.TextBox requires a use of ToolKitVB.Web.UI.Page');
}
function FormatNumberInput(obj){
    var pos = doGetPosition(obj);
    var OriginalLength = obj.value.length;
    obj.value = ToolKit.number(obj.value);
    pos = pos - (OriginalLength - obj.value.length);
    doSetPosition(obj, pos)
}
function FormatDecimalInput(obj){
    var pos = doGetPosition(obj);
    var OriginalLength = obj.value.length;
    obj.value = ToolKit.decimal(obj.value);
    pos = pos - (OriginalLength - obj.value.length);
    doSetPosition(obj, pos)
}
function FormatAlphanumericInput(obj) {
    var pos = doGetPosition(obj);
    var OriginalLength = obj.value.length;
    obj.value = ToolKit.Alphanumeric(obj.value);
    pos = pos - (OriginalLength - obj.value.length);
    doSetPosition(obj, pos)
}
function FormatPhoneUsInput(obj){
    var pos = doGetPosition(obj);
    var OriginalLength = obj.value.length;
    obj.value = ToolKit.PhoneUs(obj.value);
    pos = pos - (OriginalLength - obj.value.length);
    doSetPosition(obj, pos)
}
function FormatDateUsInput(obj) {
    var pos = doGetPosition(obj);
    var OriginalLength = obj.value.length;
    obj.value = ToolKit.DateUs(obj.value);
    pos = pos - (OriginalLength - obj.value.length);
    doSetPosition(obj, pos)
}
function FormatCurrencyInput(obj){
    obj.value = ToolKit.currency(obj.value);
}
function doGetPosition (ctrl) {
    var CaretPos = 0;
    if (document.selection) {
        ctrl.focus ();
        var Sel = document.selection.createRange ();
        Sel.moveStart ('character', -ctrl.value.length);
        CaretPos = Sel.text.length;
    }else if (ctrl.selectionStart || ctrl.selectionStart == '0') CaretPos = ctrl.selectionStart;
    return (CaretPos);
}
function doSetPosition(ctrl, pos)
{
    if(ctrl.setSelectionRange)
    {
        ctrl.focus();
        ctrl.setSelectionRange(pos,pos);
    }
    else if (ctrl.createTextRange) {
        var range = ctrl.createTextRange();
        range.collapse(true);
        range.moveEnd('character', pos);
        range.moveStart('character', pos);
        range.select();
    }
}